<script>
  import { fade } from "svelte/transition";
  export let message = "";
  export let duration = 3000; // 持续时间，单位毫秒

  let visible = false;

  const showToast = () => {
    visible = true;
    setTimeout(() => {
      visible = false;
    }, duration);
  };

  showToast(); // 显示Toast
</script>

{#if visible}
  <div class="toast" transition:fade>
    {message}
  </div>
{/if}

<style>
  .toast {
    position: fixed;
    top: 300px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background-color: #333;
    color: white;
    border-radius: 5px;
    z-index: 1000;
  }
</style>
